package tmc.app.login;

import tmc.app.data.GlobalVariables;
import tmc.app.data.ProcessData;
import tmc.app.luckydraw.ActivityLuckyDraw;
import tmc.app.luckydraw.R;
import tmc.app.luckydraw.R.layout;
import tmc.app.luckydraw.R.menu;
import android.os.Bundle;
import android.provider.Settings.Global;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;

public class ActivityLogin extends Activity {

    private EditText edt_username;
	private EditText phone;
	private EditText number;
	private ImageView img_play;
	private Activity mActivity;
	private Context mContext;

	@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        
        mActivity = this;
        mContext = this;
        initLayouts();
        initEvents();
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
    
    public void initEvents()
    {
    	img_play.setOnClickListener(onClickListener);
    }
    
    public void initLayouts()
    {
    	edt_username = (EditText)findViewById(R.id.edt_username);
    	phone = (EditText)findViewById(R.id.phone);
    	number = (EditText)findViewById(R.id.number);
    	img_play = (ImageView)findViewById(R.id.img_play);
    }
    
    public OnClickListener onClickListener = new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			// TODO Auto-generated method stub
			ProcessData.ringPhone(mActivity);
			checkLogin();
		}
	};
	
	public void onBackPressed() {};
	
	public void checkLogin()
	{
		if(!edt_username.getText().toString().equals("") && 
				!phone.getText().toString().equals("") &&
				!number.getText().toString().equals("") && !number.getText().toString().equals("0"))
		{
			GlobalVariables.hoten = edt_username.getText().toString();
			GlobalVariables.phone = phone.getText().toString();
			GlobalVariables.count = Integer.parseInt(number.getText().toString());
			GlobalVariables.lanthu = GlobalVariables.count;
			moveToPlay();
		}else{
			//show dialog
			ProcessData.showDialogThongbao(mContext, getResources().getString(R.string.txt_inputLoginErr));
		}
	}
	
	public void moveToPlay()
	{
		Intent intent = new Intent(this, ActivityLuckyDraw.class);
		startActivity(intent);
		overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right);
		finish();
	}
    
}
